// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.vehicles;

import org.joml.Vector2f;

public final class PolyPolyIntersect {
    private static Vector2f tempVector2f_1 = new Vector2f();
    private static Vector2f tempVector2f_2 = new Vector2f();
    private static Vector2f tempVector2f_3 = new Vector2f();

    public static boolean intersects(PolygonalMap2.VehiclePoly a, PolygonalMap2.VehiclePoly b) {
        for (int int0 = 0; int0 < 2; int0++) {
            PolygonalMap2.VehiclePoly vehiclePoly = int0 == 0 ? a : b;

            for (int int1 = 0; int1 < 4; int1++) {
                int int2 = (int1 + 1) % 4;
                Vector2f vector2f0 = getPoint(vehiclePoly, int1, tempVector2f_1);
                Vector2f vector2f1 = getPoint(vehiclePoly, int2, tempVector2f_2);
                Vector2f vector2f2 = tempVector2f_3.set(vector2f1.y - vector2f0.y, vector2f0.x - vector2f1.x);
                double double0 = Double.MAX_VALUE;
                double double1 = Double.NEGATIVE_INFINITY;

                for (int int3 = 0; int3 < 4; int3++) {
                    Vector2f vector2f3 = getPoint(a, int3, tempVector2f_1);
                    double double2 = (double)(vector2f2.x * vector2f3.x + vector2f2.y * vector2f3.y);
                    if (double2 < double0) {
                        double0 = double2;
                    }

                    if (double2 > double1) {
                        double1 = double2;
                    }
                }

                double double3 = Double.MAX_VALUE;
                double double4 = Double.NEGATIVE_INFINITY;

                for (int int4 = 0; int4 < 4; int4++) {
                    Vector2f vector2f4 = getPoint(b, int4, tempVector2f_1);
                    double double5 = (double)(vector2f2.x * vector2f4.x + vector2f2.y * vector2f4.y);
                    if (double5 < double3) {
                        double3 = double5;
                    }

                    if (double5 > double4) {
                        double4 = double5;
                    }
                }

                if (double1 < double3 || double4 < double0) {
                    return false;
                }
            }
        }

        return true;
    }

    private static Vector2f getPoint(PolygonalMap2.VehiclePoly vehiclePoly, int _int, Vector2f vector2f) {
        if (_int == 0) {
            return vector2f.set(vehiclePoly.x1, vehiclePoly.y1);
        } else if (_int == 1) {
            return vector2f.set(vehiclePoly.x2, vehiclePoly.y2);
        } else if (_int == 2) {
            return vector2f.set(vehiclePoly.x3, vehiclePoly.y3);
        } else {
            return _int == 3 ? vector2f.set(vehiclePoly.x4, vehiclePoly.y4) : null;
        }
    }
}
